
import java.io.Serializable;
import java.util.ArrayList;

class Request implements Serializable{

  //Request type
  private RequestType requestType;

  //In case it's a DOWNLOAD: file's location
  private String location;

  //In case it's a CONSULT: file's creator
  private String creator;

  //In case it's a CONSULT: file's title
  private String title;

  //In case it's a CONSULT or a REACHABLE_NODES: nodes already visited
  private ArrayList<String> visited = null;

  //In case it's a CONSULT the node must know how the client will reach him
  private String serverName;

  /**
   * Constructor
   * 
   * In case it's a consult, user may specify creator or title.
   * In either case he must specify the nodes already visited so
   * we make no cycles
   * 
   * @param creator  Track's creator substring
   * @param title    Track's title substring
   * @param visited  Nodes already visited in this request
   */
  Request(String creator, String title, ArrayList<String> visited, String serverName){
    this.requestType = RequestType.CONSULT;
    this.creator = creator;
    this.title = title;
    this.visited = visited;
    this.serverName = serverName;
  }

  /**
   * Constructor
   * 
   * In case it's a download, user must specify the file path
   * 
   * @param creator  Track's file location
   */
  public Request(String location){
    this.requestType = RequestType.DOWNLOAD;
    this.location = location;
  }

  /**
   * Constructor
   * 
   * In case it's a reachable node request, user must specify visited
   * nodes so we make no cycles looking for new reachable nodes
   * 
   * @param visited Nodes already discovered
   */
  Request(ArrayList<String> visited){
    this.requestType = RequestType.REACHABLE_NODES;
    this.visited = visited;
  }

  public RequestType getRequestType(){
    return requestType;
  }

  public ArrayList<String> getVisited(){
    return visited;
  }

  public String getCreator(){
    return creator;
  }

  public String getTitle(){
    return title;
  }

  public String getLocation(){
    return location;
  }

  public String getServerName(){
    return serverName;
  }

  public String toString(){
    String s = "creator: " + creator + " title: " + title + '\n';
    if (null != visited){
      s += "##################### VISITED #####################\n";
      for (String nodeName : visited){
        s += nodeName + "\n";
      }
    }
    s += " serverName: " + serverName + "location: " + location;
    return s;
  }
}